
package com.android.matmanual;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
//import android.os.Loopback;
import android.os.Handler;
import android.os.Message;

public class HeadsetLoopback extends Activity {
	
	//private Loopback mEf;
	WakeLock mWakeLock;
	MyHandler mMyHandler;
	private static final int OPEN_LB = 0;  
	private static final int CLOSE_LB = 1; 
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  setTitle(R.string.headset);
	  PowerManager pm =
		           (PowerManager) getSystemService(POWER_SERVICE); 
	  mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, 
		          "XYTEST"); 
			mWakeLock.acquire(); 				
	  //mEf = new Loopback();
	  mMyHandler = new MyHandler();
	  mMyHandler.sendEmptyMessage(OPEN_LB);
	
	}
	private class MyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			  switch (msg.what) {
			  
	        case OPEN_LB: 
	      	  //mEf.openheadsetlb();
	      	  break;
	        case CLOSE_LB:
	      	  //mEf.closeheadsetlb();	
	      	  break;
	    }
		}
	}

  
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {		 	
    	int result = TestControl.GetKeyEvent(keyCode);
		if (result != TestControl.DO_NOTHING) {
			setResult(result);
			finish();
	    }
	    return true;
	}
	 
	 
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
      finish();
		super.onStop();
	}
		
  @Override
  protected void onDestroy() {
  	// TODO Auto-generated method stub 
		if(mWakeLock!=null)
		{
			mWakeLock.release(); 
			mWakeLock = null;
		}

		mMyHandler.sendEmptyMessage(CLOSE_LB);
  	super.onDestroy();
  }	
	 
	@Override
	public void onAttachedToWindow() 
	{
		// TODO Auto-generated method stub
		super.onAttachedToWindow();
		this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
	} 
 
	
}
		 